﻿using System;
using System.Collections;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty
{
    public class BlueprintSubTrigger : MonoBehaviour
    {
        public Action<Collider> onEnter;
        public Action<Collider> onExit;
        public Action<Collider> onStay;

        private void OnTriggerEnter(Collider other)
        {
            onEnter?.Invoke(other);
        }

        private void OnTriggerExit(Collider other)
        {
            // 支持区域的多触发器，防止从一个触发器进入到另一个触发器时出现 蓝图重启的情况
            StartCoroutine(Exit(other));
        }

        IEnumerator Exit(Collider other)
        {
            yield return new WaitForSeconds(0.1f);  // TODO 最好等物理帧
            onExit?.Invoke(other);
        }

        private void OnTriggerStay(Collider other)
        {
            onStay?.Invoke(other);
        }
    }
}